use bytes::{BufMut, BytesMut};

pub trait BodyEncode {
    fn encode(self, buf: &mut BytesMut);
}

impl<T: BodyEncode + Copy> BodyEncode for &T {
    fn encode(self, buf: &mut BytesMut) {
        (*self).encode(buf);
    }
}

impl <T1: BodyEncode, T2: BodyEncode> BodyEncode for (T1, T2) {
    fn encode(self, buf: &mut BytesMut) {
        self.0.encode(buf);
        self.1.encode(buf);
    }
}

impl BodyEncode for () {
    fn encode(self, _buf: &mut BytesMut) {}
}

impl BodyEncode for u8 {
    fn encode(self, buf: &mut BytesMut) {
        buf.put_u8(self);
    }
}

impl BodyEncode for u16 {
    fn encode(self, buf: &mut BytesMut) {
        buf.put_u16(self);
    }
}

impl BodyEncode for u32 {
    fn encode(self, buf: &mut BytesMut) {
        buf.put_u32(self);
    }
}

impl BodyEncode for i32 {
    fn encode(self, buf: &mut BytesMut) {
        buf.put_i32(self);
    }
}

impl BodyEncode for &[u8] {
    fn encode(self, buf: &mut BytesMut) {
        buf.put_u8(self.len() as u8);
        buf.extend_from_slice(self);
    }
}






